// pages/home/search/components/election-item/index.js
const app = getApp()
Component({
  properties: {
    userInfo: {
      type: Object,
      value: null
    }
  },
  lifetimes: {
    attached() {
      if (this.properties.userInfo) {
        this.setData({
          userData: this.properties.userInfo,
          spaceType: this.properties.userInfo.ReleaseRequirement.SpaceType,
          subType: this.properties.userInfo.ReleaseRequirement.SpaceType,
          detail: this.properties.userInfo.ReleaseRequirement,
          status: this.properties.userInfo.Status,
          time: parseInt(this.properties.userInfo.RemainTime)
        })
        switch (this.data.status) {
          case 7: //待评选
            this.setData({
              statusImg: 'hb_dpx.svg'
            })
            break;
          case 8: //已结束
            this.setData({
              statusImg: 'hb_yjs.svg'
            })
            break;
          default:
            break;
        }
        switch (this.data.spaceType) {
          case 1: //室内
            this.setData({
              img1: this.data.detail.HouseTypeList[0]?.PictureUrl,
              img2: this.data.detail.NewSceneList[0]?.PictureList[0]?.PictureUrl,
              img3: this.data.detail.StyleReferenceList[0]?.PictureUrl,
              des: this.data.detail.WholeHouse
            })
            break;
          case 2: //建筑
            // 商业用地
            if (this.data.detail.ArchitectureLandType === 1) {
              this.setData({
                img1: this.data.detail.ProfileList[0]?.PictureUrl,
                img2: this.data.detail.NewSceneList[0]?.PictureList[0]?.PictureUrl,
                img3: this.data.detail.StyleReferenceList[0]?.PictureUrl,
                des: this.data.detail.Totality
              })
            }
            // 建筑用地
            else {
              this.setData({
                img1: this.data.detail.HouseTypeList[0]?.PictureUrl,
                img2: this.data.detail.NewSceneList[0]?.PictureList[0]?.PictureUrl,
                img3: this.data.detail.StyleReferenceList[0]?.PictureUrl,
                des: this.data.detail.Totality
              })
            }
            break;
          case 3: //景观
            this.setData({
              img1: this.data.detail.HouseTypeList[0]?.PictureUrl,
              img2: this.data.detail.NewSceneList[0]?.PictureList[0]?.PictureUrl,
              img3: this.data.detail.StyleReferenceList[0]?.PictureUrl,
              des: this.data.detail.Totality
            })
            break;
          default:
            break;
        }
      }
    }
  },
  data: {
    IMGBASEURL: app.globalData.IMGBASEURL,
    userData: null, //竞选对象
    detail: null, //竞选详情
    statusImg: '', //竞选状态图片
    spaceType: 0, //空间类型：1室内,2建筑,3景观
    subType: 0, //子空间类型
    img1: '',
    img2: '',
    img3: '',
    des: '', //描述
    time: 36000000, //倒计时毫秒
    timerShow: true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    timeFinish() {
      // console.log('倒计时结束');
      this.setData({
        timerShow: false
      })
    }
  }
})